package com.newlink.building.common_base.api

import com.newlink.building.common_base.model.bean.*
import io.reactivex.Observable
import okhttp3.MultipartBody
import retrofit2.http.*

/**
 * Created by xiaodong on 2022/8/24.
 * 后台接口API
 * 用于定义接口地址、名称、入参、出参
 *
 * 注意: 因为多语言的需要, 每个请求的最后一个参数需要携带 语言参数
 *
 */
interface Base_ApiService {
    @FormUrlEncoded
    @POST("api/sys/auth/email")
    fun login(
        @Field("email") email: String,
        @Field("password") password: String,

        ): Observable<HttpResult<LoginData>>


    @POST("api/app/login")
    fun login(

        @Header("appType") appType: Int = 1,//1 Android, 2 IOS
        @Body bean: LoginRequestBean,

        ): Observable<HttpResult<LoginResponseData>>

    @POST("api/app/sipLogin")
    fun loginBySip(
        @Body bean: LoginSipAccountRequestBean,

        ): Observable<HttpResult<LoginResponseData>>

    @PUT("api/app/rqLogin")
    fun loginWithQR(
        @Query("userName") username: String,
        @Query("password") password: String,
    ): Observable<HttpResult<LoginResponseData>>

    @POST("api/mobile/login")
    @FormUrlEncoded
    fun loginByToken(
        @Field("token") token: String,

        ): Observable<HttpResult<LoginData>>


    @POST("api/app/codeLogin")
    fun loginWithMsgCode(
        @Body bean: LoginMsgCodeBean,
    ): Observable<HttpResult<LoginResponseData>>

    @POST("api/user/register")
    @FormUrlEncoded
    fun register(
        @Field("username") username: String,
        @Field("password") password: String,

        ): Observable<HttpResult<RegisterData>>

    @GET("api/app/device/list")
    fun getDeviceList(
        @Header("Authorization") token: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int,
        @Query("devName") devName: String,
        @Query("devType") devType: Int?
//        @Body bean: DeviceRequestBean
    ): Observable<HttpResult<DeviceListData>>

    @GET("api/app/category/list")
    fun getCategoryList(
        @Header("Authorization") token: String,
    ): Observable<HttpResult<CategoryListData>>

    @GET("api/app/tempKey/list")
    fun getSecretKeyList(
        @Header("Authorization") token: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int
    ): Observable<HttpResult<SecretKeyListData>>

    @GET("api/app/tempKey/info")
    fun getSecretKeyInfo(
        @Header("Authorization") token: String,
        @Query("id") id: String,
    ): Observable<HttpResult<SecretKeyData>>

    @POST("api/app/tempKey")
    fun addSecretKey(
        @Header("Authorization") token: String,
        @Body data: SecretKeyAddData,
    ): Observable<HttpResult<StatusData>>

    @HTTP(method = "DELETE", path = "api/app/tempKey", hasBody = true)
    fun deleteSecretKey(
        @Header("Authorization") token: String,
        @Body ids: MutableList<String>,
    ): Observable<HttpResult<StatusData>>

    @POST("api/mobile/RQ")
    @FormUrlEncoded
    fun getQRCode(
        @Field("phoneNo") iphone: String,
        @Field("devieId") devieId: String,

        ): Observable<HttpResult<SecretQRCodeData>>

    @GET("api/mobile/RQ")
    fun getQRCode(
        @Query("flag") flag: Boolean,

        ): Observable<HttpResult<String>>

    @GET("api/app/users/checkToken")
    fun checkTokenAvailable(
        @Header("Authorization") token: String,
    ): Observable<Base_BaseBean>

    /**
     * ------------------------------------------我的------------------------------------------------
     */
    //获取用户详情
    @GET("api/app/user/userInfo")
    fun getUserInfo(
        @Header("Authorization") token: String,
        @Query("userId") userId: Long,

        ): Observable<HttpResult<UserInfoData>>

    @GET("api/app/user/userInfo")
    fun getUserInfoNew(
        @Header("Authorization") token: String,
        @Query("userId") userId: Long,
    ): Observable<HttpResult<UserInfoResp>>

    //获取物业和系统消息的未读/已读数量
    @GET("api/app/msg/count")
    fun getUnreadFlag(
        @Header("Authorization") token: String,
        @Query("type") type: Int = 1,//1.未读 2.已读
    ): Observable<HttpResult<MessageReadResult>>

    //获取系统消息未读/已读数量 (弃用)
    @GET("api/app/notice/count")
    fun getNoticeUnreadFlag(
        @Header("Authorization") token: String,
        @Query("type") type: Int = 1,//1.未读 2.已读
    ): Observable<HttpResult<Int>>

    @GET("api/app/kcpInfo")
    fun getKcpInfo(
        @Header("Authorization") token: String,
        @Query("userId") userId: Long,
    ): Observable<HttpResult<KcpInfoData>>

//    @GET("/mqtt/appCfg")
//    fun getMqttInfo(
//        @Header("Authorization") token: String,
//        ): Observable<HttpResult<MqttData>>

    @GET("api/cfg/app")
    fun getAppConfig(
        @Header("Authorization") token: String,
    ): Observable<HttpResult<AppConfigData>>

    //获取用户详情 —— 缺少是否有新消息的参数

    //退出登录
    @GET("api/app/logout")
    fun logout(
        @Header("Authorization") token: String,
    ): Observable<HttpResult<Boolean>>

    @GET("api/app/token/refresh")
    fun refreshToken(
        @Query("userId") userId: Long,
        @Query("token") token: String,

        ): Observable<HttpResult<DefaultData>>

    //设置/修改头像——先调用上传文件接口，再调用setUserInfo接口
    @Multipart
    @POST("api/app/users/upload")
    fun uploadAvatar2(
        @Header("Authorization") token: String,
        @Part body: MultipartBody.Part,

        ): Observable<HttpResult<AvatarResponse>>

    //修改密码
    @POST("api/app/user/updatePwd")
    fun changePassword(
        @Header("Authorization") token: String,
        @Body changePasswordBean: Base_ChangePasswordBean,

        ): Observable<HttpResult<String?>>

    //忘记密码
//    @FormUrlEncoded
//    @PUT("app/users/sendPwdEmail")
//    fun sendPwdEmail(
//        @Field("email") email: String,
//    ): Observable<HttpResult<CommonData>>

    @FormUrlEncoded
    @PUT("api/app/user/sendPwdEmail")
    fun sendPwdEmail(
        @Field("email") email: String,
        @Field("userCategory") userCategory: Int
    ): Observable<HttpResult<String?>>

    @GET("api/app/user/checkCode")
    fun sendVerifyCode(
        @Query("code") code: String,
        @Query("email") email: String,
    ): Observable<HttpResult<Boolean?>>

    @GET("api/app/checkVersion")
    fun checkNewVersion(
        @Header("Authorization") token: String,
        @Query("version") version: Int,
        @Query("type") type: Int,
    ): Observable<HttpResult<VersionBean>>

    @POST("api/app/user/setPwd")
    fun sendNewPwd(
        @Body pwdBean: NewPasswordBean,
    ): Observable<HttpResult<String?>>

    //    @FormUrlEncoded
    @PUT("api/app/users/info")
    fun syncUserInfo(
        @Header("Authorization") token: String,
        @Body userInfoData: UpdateAvatarBean,

        ): Observable<HttpResult<UserInfoData>>


    //编辑用户详情（头像、用户名、手机号）
    @PUT("api/app/users/info")
    fun setUserInfo(
        @Header("Authorization") token: String,
        @Body setUserInfoBean: SetUserInfoBean,

        ): Observable<HttpResult<UserInfoData>>

    @FormUrlEncoded
    @PUT("api/app/user/updateNickname")
    fun setUserNickName(
        @Header("Authorization") token: String,
        @Field("userId") userId: String,
        @Field("nickName") nickName: String,
    ): Observable<HttpResult<ResponseTopData>>

    //删除账号
    @FormUrlEncoded
    @PUT("api/app/user/writeOff")
    fun deleteAccount(
        @Header("Authorization") token: String,
        @Field("userId") userId: String,
        @Field("masterFlag") masterFlag: Boolean
    ): Observable<HttpResult<ResponseTopData>>

    //获取消息列表
    @GET("api/app/msg/list")
    fun getMessageList(
        @Header("Authorization") token: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int,

        ): Observable<HttpResult<MessageListData>>

    //消息列表 —— 全部删除
    @POST("api/app/msg/clean")
    fun deleteAllMessageList(
        @Header("Authorization") token: String,

        ): Observable<HttpResult<DefaultData>>

    //消息中心 —— 将未读消息修改为已读状态
    @POST("api/app/msg/read")
    fun setMessageReadStatus(
        @Header("Authorization") token: String,
        @Body ids: MutableList<Long>
    ): Observable<HttpResult<ResponseTopData>>


//    @GET("app/read")
//    fun setMessageReadStatus(
//        @Header("Authorization") token: String,
//        @Query("id") msgId: Long,
//
//        ): Observable<HttpResult<DefaultData>>

    //获取家庭成员列表
    @GET("api/app/user/family/list")
    fun getFamilyManagementList(
        @Header("Authorization") token: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int,
    ): Observable<HttpResult<FamilyListData>>

    @GET("api/app/user/getUserMax")
    fun getFamilyMaxMemberCount(
        @Header("Authorization") token: String,
        @Query("masterUserId") masterUserId: Long,
        @Query("prjType") prjType: Int,
    ): Observable<HttpResult<Int>>

    //添加家庭成员
    @POST("api/app/user/family")
    fun addFamilyManagement(
        @Header("Authorization") token: String,
        @Body addFamilyManagementBean: Base_AddFamilyManagementBean,
    ): Observable<HttpResult<AddFamilyManagementData>>

    //删除家庭成员
    @DELETE("api/app/user/family")
    fun deleteFamilyManagement(
        @Header("Authorization") token: String,
        @Query("userId") userId: String,
    ): Observable<HttpResult<DefaultData>>

    //获取通话设置
    @GET("api/app/users/setting")
    fun getCallSetting(
        @Header("Authorization") token: String,

        ): Observable<HttpResult<CallSettingData>>

    //设置呼叫偏好

    /**
     * ------------------------------------------记录------------------------------------------------
     */
    //获取开门记录列表
    @GET("api/app/record/door")
    fun getOpenDoorRecordList(
        @Header("Authorization") token: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int,

        ): Observable<HttpResult<OpenDoorRecordData>>

    //获取呼叫记录列表
    @GET("api/app/record/call")
    fun getCallRecordList(
        @Header("Authorization") token: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int,
        @Query("sip") sip: String,

        ): Observable<HttpResult<CallRecordData>>

    //获取安防记录列表
    @GET("api/app/record/security")
    fun getSecurityRecordList(
        @Header("Authorization") token: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int
    ): Observable<HttpResult<SecurityRecordData>>

    //获取截图记录列表
    @GET("api/app/record/videoList")
    fun getCaptureVideoList(
        @Header("Authorization") token: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int,
        @Query("order") order: String,
        @Query("asc") asc: Boolean,

        ): Observable<HttpResult<CaptureVideoListData>>

    //删除记录
    @DELETE("api/app/record")
    @FormUrlEncoded
    fun deleteRecord(
        @Field("phoneNo") iphone: String,
        @Field("devieId") devieId: String,

        ): Observable<HttpResult<DeleteRecordData>>

    @GET("api/app/device/door")
    fun getDoorInfo(
        @Header("Authorization") token: String,
        @Query("mac") mac: String,

        ): Observable<HttpResult<MutableList<DoorData>>>

    //获取用户登录二维码
    @GET("api/app/user/qrcode")
    fun getUserQrCode(
        @Header("Authorization") token: String,
        @Query("userId") id: Long
    ): Observable<HttpResult<UserQrCodeData>>

    @GET("api/app/code")
    fun getVerifyCode(
        @Query("area") area: String,
        @Query("mobile") mobile: String
    ): Observable<HttpResult<ResponseTopData>>

    @GET("api/app/user/bindCode")
    fun getBindCode(
        @Header("Authorization") token: String,
        @Query("area") area: String,
        @Query("mobile") mobile: String
    ): Observable<HttpResult<ResponseTopData>>

    @FormUrlEncoded
    @PUT("api/app/user/bindMobile")
    fun bindMobile(
        @Header("Authorization") token: String,
        @Field("area") area: String,
        @Field("mobile") mobile: String,
        @Field("userId") userId: Long,
        @Field("code") code: String
    ): Observable<HttpResult<ResponseTopData>>

    @GET("api/app/verify")
    fun updateOpenDoorPassword(
        @Header("Authorization") token: String,
        @Query("password") password: String
    ): Observable<HttpResult<DefaultData>>

    @GET("api/app/notice/list")
    fun getFlsMessageList(
        @Header("Authorization") token: String,
        @Query("page") page: Int,
        @Query("limit") limit: Int

    ): Observable<HttpResult<FlsMessageListData>>

    //消息中心/系统消息 —— 将未读消息修改为已读状态
    @POST("api/app/notice/read")
    fun setFlsMessageReadStatus(
        @Header("Authorization") token: String,
        @Body ids: MutableList<Long>
    ): Observable<HttpResult<ResponseTopData>>

    @POST("api/app/notice/clean")
    fun deleteAllFlsMessageList(
        @Header("Authorization") token: String,
    ): Observable<HttpResult<ResponseTopData>>

    @POST("api/app/authKey/faceCheck")
    fun checkFaceValid(
        @Header("Authorization") token: String,
        @Body bean: FaceInfoBean
    ): Observable<HttpResult<Boolean>>

    @POST("api/app/checkPwd")
    fun verifyPassword(
        @Header("Authorization") accessToken: String,
        @Body password: String
    ): Observable<HttpResult<ResponseTopData>>

    @GET("api/app/authKey/list")
    fun getAuthKeyList(
        @Header("Authorization") token: String,
        @Query("keyType") keyType: Int,//1.卡2.密码3.人像
        @Query("page") page: Int = 0,
        @Query("limit") limit: Int = 1000
    ): Observable<HttpResult<FaceListData>>

    @POST("api/app/authKey")
    fun addAuthKey(
        @Header("Authorization") token: String,
        @Body bean: AuthRequestBody
    ): Observable<HttpResult<StatusData>>

    @PUT("api/app/authKey")
    fun modifyAuthKey(
        @Header("Authorization") token: String,
        @Body bean: AuthModifyBody
    ): Observable<HttpResult<String>>

    @HTTP(method = "DELETE", path = "api/app/authKey", hasBody = true)
    fun deleteAuthKey(
        @Header("Authorization") token: String,
        @Body ids: MutableList<String>,
    ): Observable<HttpResult<StatusData>>

    @GET("api/app/renewal")
    fun updateToken(
        @Header("Authorization") token: String,
    ): Observable<Base_BaseBean>

    @POST("api/kit")
    fun kitRegister(
        @Body reqeust: KitRegisterRequest,
    ): Observable<HttpResult<RegisterResultData>>

    @PUT("api/kit/device")
    fun editDevice(
        @Header("Authorization") token: String,
        @Body deviceData: KitDeviceEditData,
    ): Observable<HttpResult<StatusData>>

    @POST("api/kit/device")
    fun addKitDevice(
        @Header("Authorization") token: String,
        @Body deviceData: KitDeviceData,
    ): Observable<HttpResult<StatusData>>


    //    @HTTP(method = "DELETE", path = "api/kit/device", hasBody = true)
    @DELETE("api/kit/device/{mac}")
    fun deleteKitDevice(
        @Header("Authorization") token: String,
        @Path("mac") mac: String,
    ): Observable<HttpResult<StatusData>>

    @POST("api/app/code")
    fun getKitVerifyCode(
        @Body request: VerifyCodeRequest
    ): Observable<HttpResult<ResponseTopData>>

    @POST("api/app/user/kitSetPwd")
    fun sendNewKitPwd(
        @Header("Authorization") token: String,
        @Body pwdBean: NewKitPasswordBean,
    ): Observable<HttpResult<String?>>

    @GET("api/app/areaCode")
    fun getAreaCode(): Observable<HttpResult<MutableList<AreaCodeData>>>

    @PUT("api/app/user/updateEmail")
    fun updateEmail(
        @Header("Authorization") token: String,
//        @Body emailData: EmailData,
        @Query("userId") userId: Long,
        @Query("email") email: String,
    ): Observable<HttpResult<StatusData>>

    @GET("api/app/record/missedCalls")
    fun getMissedCalls(
        @Header("Authorization") token: String,
    ): Observable<HttpResult<Int>>

    @POST("api/app/record/read")
    fun readMissedCalls(
        @Header("Authorization") token: String,
        @Body request: RecordMessageReadRequest
    ): Observable<Base_BaseBean>

    @GET("api/app/manager/prj")
    fun getPrjList(
        @Header("Authorization") token: String
    ): Observable<HttpResult<MutableList<ProjectData>>>

    @GET("api/app/manager/unit")
    fun getUnitList(
        @Header("Authorization") token: String,
        @Query("prjId") prjId: String,
        @Query("unitName") unitName: String = ""
    ): Observable<HttpResult<MutableList<UnitData>>>

    @GET("api/app/manager/room")
    fun getRoomList(
        @Header("Authorization") token: String,
        @Query("unitId") unitId: String,
        @Query("roomName") roomName: String = ""
    ): Observable<HttpResult<MutableList<RoomData>>>

    @GET("api/app/manager/appUser")
    fun getRoomUserList(
        @Header("Authorization") token: String,
        @Query("roomId") roomId: String,
        @Query("name") name: String = ""
    ): Observable<HttpResult<MutableList<RoomUserData>>>

    @GET("api/app/manager/propertyUser")
    fun getPropertyManagerList(
        @Header("Authorization") token: String,
        @Query("roomId") roomId: String,
        @Query("name") name: String = ""
    ): Observable<HttpResult<MutableList<PropertyManagerData>>>

    //    @FormUrlEncoded
    @Multipart
    @POST("api/app/feedback/submit")
    fun sendFeedback(
        @Header("Authorization") token: String,
//        @Part request: FeedbackRequest,
//        @Field("deviceType") deviceType: String,
//        @Field("description") description: String,
//        @Field("contactInfo") contactInfo: String,
        @Part parts: List<MultipartBody.Part>
    ): Observable<HttpResult<Any?>>

    @GET("api/app/record/unreadPrompt")
    fun getRecordUnreadPrompt(
        @Header("Authorization") token: String,
        @Query("prjId") prjId: Long
    ): Observable<HttpResult<RecordMessageReadResult>>

    //忘记密码发送手机验证码
    @FormUrlEncoded
    @PUT("api/app/user/sendForgetPwdMobile")
    fun sendForgetPwdMobile(
        @Field("area") area: String,
        @Field("mobile") mobile: String,
        @Field("userCategory") userCategory: Int = 1//区分用户类型：1:普通FCMSApp用户 2：kit套件App用户 3：物业管理员App用户（不传默认普通用户）
    ): Observable<HttpResult<Boolean?>>

    @GET("api/app/user/checkMobileCode")
    fun checkMobileCode(
        @Query("area") area: String,
        @Query("mobile") mobile: String,
        @Query("code") code: String
    ): Observable<HttpResult<Boolean?>>

}